package com.spring.springZookeeper.controller;

import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.data.Stat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.spring.springZookeeper.common.ZkUtil;

@RestController
public class ZkController {

	@Autowired
	private ZkUtil zkutil;
	private CuratorFramework client=zkutil.client();
	
	@RequestMapping("create")
	public void create(String path,String data) throws Exception{
		zkutil.create(client, path, data);
	}
	@RequestMapping("getData")
	public String getData( String path) throws Exception{
		return zkutil.query(client, path);
	}
	@RequestMapping("setData")
	public void setData(String path,String data) throws Exception{
		zkutil.update(client, path, data);
	}
	@RequestMapping("delete")
	public void delete(String path,String data) throws Exception{
		zkutil.delete(client, path);
	}
	@RequestMapping("getStat")
	public Stat getStat(String path) throws Exception{
		return zkutil.getStat(client, path);
	}
	
	@RequestMapping("status")
	public void status(){
		zkutil.status();
	}
}
